package com.atguigu.spzx.user.controller;

import com.atguigu.spzx.model.dto.h5.UserRegistDto;
import com.atguigu.spzx.model.entity.h5.UserInfo;
import com.atguigu.spzx.model.vo.common.Result;
import com.atguigu.spzx.user.service.UserInfoService;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import jakarta.annotation.Resource;
import org.springframework.web.bind.annotation.*;

import java.util.Map;

@RestController
@Tag(name = "用户模块")
@RequestMapping("/api/user/userInfo")
public class UserInfoController {
    @Resource
    UserInfoService userInfoService;
    // /register
    @PostMapping("/register")
    @Operation(summary = "用户注册接口")
    public Result register(@RequestBody UserRegistDto userRegistDto){
        userInfoService.register(userRegistDto);
        return Result.ok();
    }
    @PostMapping("/login")
    @Operation(summary = "用户登录接口")
    public Result login(@RequestBody UserInfo userInfo){
        String token = userInfoService.login(userInfo);
        return Result.ok().data(token);
    }
    //  /api/*/auth/**   api表示用户访问，auth表示当前接口需要登录后才可以访问
    @Operation(summary = "查询登录信息回显接口")
    @GetMapping("/auth/getCurrentUserInfo")
    public Result getCurrentUserInfo(){
        //网关过滤器校验登录状态，未登录不放行
        //在通过拦截器获取登录信息透传给当前接口
        Map<String,String> userInfo = userInfoService.getCurrentUserInfo();
        return Result.ok().data(userInfo);
    }
}
